package aufgabe2;

public class MatrixArray implements MatrixInterface<MatrixArray> {

	private double[][] matrix;

	MatrixArray(double[][] matrix) {
		this.matrix = matrix;
	}

	@Override
	public void add(MatrixArray m) {
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length; j++) {
				matrix[i][j] = matrix[i][j] + m.getMatrixStructure()[i][j];
			}

		}
	}

	@Override
	public void skaMul(double f) {
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length; j++) {
				matrix[i][j] = matrix[i][j] * f;
			}
		}

	}

	@Override
	public void mul(MatrixArray m) {
		double[][] temp = new double[matrix.length][matrix[0].length];
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length; j++) {
				for(int k = 0; k < matrix[0].length;k++){
				temp[i][j] = temp[i][j] + matrix[i][k] * m.getMatrixStructure()[k][j];
				}
			}

		}
		matrix = temp;
	}

	@Override
	public void pow(int i) {
		MatrixArray erg = new MatrixArray(matrix);
		for(int j = 0; j < i-1 ; j++){
			erg.mul(this);
		}
		matrix = erg.getMatrixStructure();
	}

	public double[][] getMatrixStructure() {
		return matrix;
	}

	public String toString(){
		StringBuilder str = new StringBuilder();
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length; j++) {
				str.append(matrix[i][j] + " ");
			}
			str.append("\n");
		}
		return str.toString();
	}
	
	public boolean equals(MatrixArray m){
		for (int i = 0; i < matrix.length; i++) {
			for (int j = 0; j < matrix[0].length; j++) {
				if(matrix[i][j] != m.getMatrixStructure()[i][j]) return false;
			}
		}
		return true;
	}
}
